<template>
	<div class="allcontent">
		<div class="search">
			<el-form @submit.native.prevent  :model="searchParam" ref="queryFormRef">
				<el-row gutter="10">
					<el-col span="8">
						<el-form-item prop="tagName">
							<el-input  @keyup.enter.native="search" placeholder="请输入名称模糊搜索"  v-model="searchParam.tagName"></el-input>
						</el-form-item>
					</el-col>
					<el-col  span="8">
						<el-button type="primary" @click="search">搜索</el-button>
					</el-col>
					<el-col  span="8">
						<el-button type="info" @click="reset(queryFormRef)">重置</el-button>
					</el-col>
				</el-row>
			</el-form>
		</div>
		<div class="el-table">
			<el-table :data="tableData" style="width: 100%;">
        <el-table-column prop="ip" label="IP"/>
        <el-table-column prop="ipLocation" label="IP地点" />
        <el-table-column prop="browser" label="浏览器类型"/>
        <el-table-column prop="os" label="操作系统"/>
        <el-table-column prop="sessionId" label="SESSION ID"/>
				<el-table-column prop="createTime" label="创建时间">
					<template #default="scope">
						{{formatTimestamp(scope.row.createTime)}}
					</template>
				</el-table-column>
			</el-table>
		</div>
    <div class="el-pager">
      <el-pagination layout="total,sizes,prev, pager, next,jumper" :total="total"
                     :page-sizes="[10,20,30,40,50]" :pager-count="11"
                     size="default"  background  class="mt-4" :current-page="currentPage"
                     @size-change="handleSizeChange" @current-change="handleCurrentChange"/>
    </div>
	</div>
</template>

<script setup lang="ts">
	import {ref,reactive, onMounted} from 'vue'
  import {ElMessage, type FormInstance} from 'element-plus'
	import {useUserStore} from '@/stores/user.ts'
	import {formatTimestamp} from '@/utils/date.ts'
  import {InfoFilled} from "@element-plus/icons-vue";
  import {page}  from '@/api/uv.ts'
	const userStore = useUserStore()
	const searchParam =reactive({
		tagName:null,
    page:1,
    limit:10
	})
	const search=()=>{
		loadData()
	}
	const queryFormRef=ref<FormInstance>();
	const reset = (formEl: FormInstance | undefined) => {
		  if (!formEl) return
		  formEl.resetFields()
		  loadData();
	}
  const tableData = ref([]);
	const loading = ref(false);
  const total= ref(0);
	const loadData=()=>{
		loading.value=true;
		page(searchParam).then((res)=>{
			if(res.code === 200){
				tableData.value = res.data.list;
        total.value = res.data.total;
			}
			loading.value=false;
		})
	}
	onMounted(()=>{
		loadData();
	})
  const currentPage = ref(1)
  const handleSizeChange = (val: number) => {
    searchParam.limit= val;
    loadData();
  }
  const handleCurrentChange = (val: number) => {
    currentPage.value= val;
    searchParam.page= val;
    loadData();
  }
</script>

<style scoped>
  .el-pager{
    padding: 2%;
    justify-content: right;
  }
	.search{
		margin-bottom: 10px;
	}
	.allcontent{
		height: 65vh;
		position: relative;
	}
	.el-table{
		max-height:70%;
		overflow: auto;
	}
	.el-table::-webkit-scrollbar{
		display: none;
	}
</style>